package game;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Point2D;

public class Hud extends AnimatedSprite{

	private static final long serialVersionUID = 1L;
	
	public HudItem bar;
	HudItem bullet;

	Point fixedPosition;
	float timer;
	int qtdMines;
	Point posSangueNaBarra = new Point(85, 23);
	
	public Hud(Point position, int qtdMines) 
	{
		super(2, position,new Point(168, 78), new Point(0, 0),
				new Point(168, 78), new Point(2,1), 0.2f, false);
		this.fixedPosition = position;
		super.setImage(2);
		this.qtdMines = 5;
		this.animationType.y = 0;
		bar = new HudItem(new Point(
				(int)position.getX() + posSangueNaBarra.x,
				(int)position.getY() + posSangueNaBarra.y), new Point(76, 15)
		);
		bar.setImage(28);
	}
	
	@Override 
	public void Update()
	{	
		

		
		super.Update(true);
		
		this.timer += Time.getInstance().getLoopTime();
	
		if(bar.hp/bar.maxHp <= 0.3f && animationType.y != 1)
			this.animationType.y = 1;
		
		bar.position = new Point((int)position.getX() + posSangueNaBarra.x, (int)position.getY() + posSangueNaBarra.y);
		
		bar.Update();


		
	}
	
	public void UpdatePosition(Player player, int intMine)
	{		
		this.qtdMines = intMine;
		
		if(player.ColisaoRect(new Rectangle(0,0,200,200)))
		{
			if(position.getX() >= fixedPosition.getX() - dimension.getX())
				position = new Point2D.Double( position.getX() - 3.5f, position.getY());
		}
		else if(position.getX() < fixedPosition.getX())
		{
			position = new Point2D.Double(position.getX() + 1, position.getY());
		}
		
	}
	@Override
	public void draw(Graphics2D g2d)
	{
		super.draw(g2d);
		
		bar.draw(g2d);
		//System.out.println(qtdMines);
		for(int i =0; i< qtdMines; i++)
			g2d.drawImage(LoadImages.getImage(71),
					(int)(this.position.getX()+ 87 + i*12),
					(int)(this.position.getY() + 43),
					10,
					17,
					null);
	}
}
